package com.analysis.client;

import com.alibaba.cloud.ai.dashscope.agent.DashScopeAgent;
import com.alibaba.cloud.ai.dashscope.api.DashScopeAgentApi;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.analysis.config.CommonConstant;
import com.analysis.enums.ModelChatClientEnum;
import com.analysis.utils.RedisChatMemory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 提供不同模型的ChatClient配置
 */
@Configuration
public class AiChatClientConfig {

    /**
     * 通义千问模型
     */
    @Bean("qwenChatClient")
    public ChatClient qwenChatClient(DashScopeChatModel dashScopeChatModel) {
        ChatClient.Builder dashScopeBuilder = ChatClient.builder(dashScopeChatModel);
        return dashScopeBuilder
//                .defaultAdvisors(MessageChatMemoryAdvisor.builder(new RedisChatMemory(
//                        "127.0.0.1",
//                        6379,
//                        null)).build())
                .defaultOptions(
                        DashScopeChatOptions.builder()
                                .withEnableSearch(true)
                                .withTemperature(0.2)
                                .build()
                ).build();
    }


    /**
     * 豆包模型
     */
    @Bean("doubaoChatClient")
    public ChatClient doubaoChatClient(OpenAiChatModel openAiChatModel) {
        ChatClient.Builder builder = ChatClient.builder(openAiChatModel);
        return builder
//                .defaultAdvisors(MessageChatMemoryAdvisor.builder(new RedisChatMemory(
//                        "127.0.0.1",
//                        6379,
//                        null)).build())
//                .defaultAdvisors(new SimpleLoggerAdvisor())
//                .defaultSystem(CommonConstant.BRAND_EXPOSURE_DEFAULT_SYSTEM)
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .temperature(0.2)
                                .model(ModelChatClientEnum.DOUBAO.getModel())
                                .build()
                )
                .build();
    }


    /**
     * KIMI
     */
    @Bean("kimiChatClient")
    public ChatClient kimiChatClient(OpenAiChatModel openAiChatModel) {
        ChatClient.Builder builder = ChatClient.builder(openAiChatModel);
        return builder
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .temperature(0.2)
                                .model(ModelChatClientEnum.KIMI.getModel())
                                .build()
                )
                .build();
    }


    /**
     * 腾讯元宝混元模型
     */
    @Bean("yuanbaoChatClient")
    public ChatClient yuanbaoChatClient(OpenAiChatModel openAiChatModel) {
        ChatClient.Builder builder = ChatClient.builder(openAiChatModel);
        return builder
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .temperature(0.2)
                                .model(ModelChatClientEnum.YUANBAO.getModel())
                                .build()
                )
                .build();
    }

    /**
     * DeepSeek模型
     */
    @Bean("deepseekChatClient")
    public ChatClient deepseekChatClient(OpenAiChatModel openAiChatModel) {
        ChatClient.Builder builder = ChatClient.builder(openAiChatModel);
        return builder
//                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .temperature(0.2)
                                .model(ModelChatClientEnum.DEEPSEEK.getModel())
                                .build()
                )
                .build();
    }

    /**
     * 百度：问心一言
     */
    @Bean("baiduChatClient")
    public ChatClient baiduChatClient(OpenAiChatModel openAiChatModel) {
        ChatClient.Builder builder = ChatClient.builder(openAiChatModel);
        return builder
//                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultSystem(CommonConstant.BRAND_EXPOSURE_DEFAULT_SYSTEM)
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .temperature(0.2)
                                .model(ModelChatClientEnum.BAIDU.getModel())
                                .build()
                )
                .build();
    }


//    /**
//     * openAI模型
//     */
//    @Bean("openAiChatClient")
//    public ChatClient openAiChatClient(ChatClient.Builder builder) {
//        return builder
////                .defaultAdvisors(new SimpleLoggerAdvisor())
//                .defaultSystem(CommonConstant.BRAND_EXPOSURE_DEFAULT_SYSTEM)
//                .defaultOptions(
//                        OpenAiChatOptions.builder()
//                                .temperature(0.2)
//                                .model(ModelChatClientEnum.OPEN_AI.getModel())
//                                .build()
//                )
//                .build();
//    }
}
